package com.y.mytest;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.net.*;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@SpringBootTest
class MyIPTests2 {

    @Test
    void contextLoads() {
        String s = "  ";//.replaceAll("[\\s*\t\n\r]", "")
        System.out.println("".equals(s.trim()));
    }


    public static Optional<Inet4Address> ip() throws SocketException {
        try (final DatagramSocket socket = new DatagramSocket()) {
            socket.connect(InetAddress.getByName("8.8.8.8"), 10001);
            if (socket.getLocalAddress() instanceof Inet4Address) {
                return Optional.of((Inet4Address) socket.getLocalAddress());
            }
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        return Optional.empty();
    }

    @Test
    void test11() throws ParseException, SocketException {
        String ip = ip().toString();
        System.out.println(ip.substring(10, ip.length() - 1));
    }

    @Test
    void test12() throws ParseException {
        System.out.println(System.currentTimeMillis());                                                //隔的天数
        System.out.println(System.currentTimeMillis() / 1000);                                                //隔的天数
        if ("1acccess1".contains("acccess")) {
            System.out.println(true);
        }
        List<String> cities = Arrays.asList("Milan",
                "London",
                "New York",
                "San Francisco");
        String citiesCommaSeparated = String.join(",", cities);
        System.out.println(citiesCommaSeparated);
    }

}
